package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherService {
    TeacherDao teacherDao = new TeacherDao();


    public boolean addTeacher(Teacher t) {
        return teacherDao.addTeacher(t);

    }

    public boolean isExists(String id) {
        Teacher[] teachers = teacherDao.findAllTeacher();
        boolean flag = false;
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if(teacher !=null&&teacher.getId().equals(id)){
                flag = true;
                break;
            }
        }
        return flag;
    }

    public Teacher[] findAllTeacher() {
        Teacher[] teachers = teacherDao.findAllTeacher();
        boolean flag = false;
        for (int i = 0; i < teachers.length; i++) {
            Teacher t = teachers[i];
            if(t!=null){
                flag = true;
                break;
            }
        }
        if(flag){
            return teachers;
        }else{
            return null;
        }

    }

    public void deleteTeacher(String delId) {
        teacherDao.deleteTeacher(delId);
    }

    public void updateTeacher(String updateId, Teacher t) {
        teacherDao.updateTeacher(updateId,t);
    }
}
